package com.wechat.page.contact.misc;

import org.controlsfx.glyphfont.FontAwesome;

import com.swak.fx.support.ui.UIIcon;
import com.swak.fx.support.ui.UILifecycle;

import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

public class OpsThumb extends GridPane implements UILifecycle {

	private final String[] STYLE_CLASS = { "contact-thumb" };

	private UIIcon image;
	private Text name;

	public OpsThumb(FontAwesome.Glyph icon, String text) {
		this.getStyleClass().addAll(STYLE_CLASS);
		this.image = new UIIcon(icon);
		this.name = new Text(text);
		this.init();
	}

	@Override
	public void initializeParts() {
		this.image.getStyleClass().add("contact-thumb__image");
		this.image.setPrefSize(48, 48);

		this.name.setTextAlignment(TextAlignment.CENTER);
		this.name.getStyleClass().add("contact-thumb__name");
		this.add(image, 0, 0);
		this.add(name, 0, 1);

		this.setPrefSize(54, 69);
		GridPane.setHgrow(this.image, Priority.ALWAYS);
		GridPane.setVgrow(this.image, Priority.NEVER);
		GridPane.setHalignment(this.image, HPos.CENTER);
		GridPane.setValignment(this.image, VPos.CENTER);
		GridPane.setMargin(this.image, new Insets(0, 0, 3, 0));

		GridPane.setFillHeight(this.name, false);
		GridPane.setHgrow(this.name, Priority.ALWAYS);
		GridPane.setVgrow(this.name, Priority.ALWAYS);
		GridPane.setHalignment(this.name, HPos.CENTER);
		GridPane.setValignment(this.name, VPos.CENTER);
	}

	@Override
	public void setupBindings() {
		UILifecycle.super.setupBindings();
	}

	@Override
	public void setupValueChangedListeners() {
		UILifecycle.super.setupValueChangedListeners();
	}

	@Override
	public void setupEventHandlers() {
		UILifecycle.super.setupEventHandlers();
		this.addEventHandler(MouseEvent.MOUSE_CLICKED, this.mouseClickHandler);
	}

	private void onMouseClick(MouseEvent event) {
	}

	@Override
	public void initializeFinish() {
		UILifecycle.super.initializeFinish();
	}

	// ================================================================================
	// Event
	// ================================================================================
	EventHandler<MouseEvent> mouseClickHandler = (e) -> this.onMouseClick(e);
}
